<html>
<head><meta charset="utf-8"><title>const-generics: literal params · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html">const-generics: literal params</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="191939991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191939991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191939991">(Mar 26 2020 at 19:54)</a>:</h4>
<p>I currently want to implement literals as const params without requiring a block.</p>
<p>This implements the following <code>FIXME</code>:  <a href="https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_parse/parser/path.rs#L440-L442" title="https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_parse/parser/path.rs#L440-L442">https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_parse/parser/path.rs#L440-L442</a></p>
<p>Do we want to support arbitrary paths as const params without needing blocks or only identifiers.</p>
<p>i.e. should this be valid</p>
<div class="codehilite"><pre><span></span><span class="k">mod</span> <span class="nn">inner</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">C</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">type</span> <span class="nc">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="o">&lt;</span><span class="n">inner</span>::<span class="n">C</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</pre></div>



<a name="191941309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941309">(Mar 26 2020 at 20:04)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="121053">@varkor</span> <span class="user-mention" data-user-id="256759">@boats</span></p>



<a name="191941402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941402">(Mar 26 2020 at 20:05)</a>:</h4>
<p>I thought something like this was implemented already?</p>



<a name="191941445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941445">(Mar 26 2020 at 20:05)</a>:</h4>
<p>it's in <code>librustc_ast_lowering</code> IIRC</p>



<a name="191941470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941470">(Mar 26 2020 at 20:05)</a>:</h4>
<p>(but limited to single segment paths, I think?)</p>



<a name="191941574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941574">(Mar 26 2020 at 20:06)</a>:</h4>
<p>There was some problem,  give me a second</p>



<a name="191941756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941756">(Mar 26 2020 at 20:08)</a>:</h4>
<p>This only works if the identifier does not exist in the type namespace: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=7853b8ddb6eba2a9b2ca1c857411776f" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=7853b8ddb6eba2a9b2ca1c857411776f">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=7853b8ddb6eba2a9b2ca1c857411776f</a></p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(const_generics)]</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">C</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">C</span><span class="p">;</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">type</span> <span class="nc">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="o">&lt;</span><span class="n">C</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</pre></div>


<p>this fail atm</p>



<a name="191941999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191941999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191941999">(Mar 26 2020 at 20:09)</a>:</h4>
<p>I think that's intentional?</p>



<a name="191942069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942069">(Mar 26 2020 at 20:10)</a>:</h4>
<p>not entirely sure though, I think <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> mentored the implementation</p>



<a name="191942220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942220">(Mar 26 2020 at 20:11)</a>:</h4>
<p>I've seen this mentioned in some issues at least and I would be quite disappointed if this were true. <del>Especially since it would prevent us from using unit structs in const generics</del> it doesnt</p>



<a name="191942469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942469">(Mar 26 2020 at 20:13)</a>:</h4>
<blockquote>
<p>I think that's intentional?</p>
</blockquote>
<p>it wasn't intentional, but it was suggested that fixing this would be difficult</p>



<a name="191942506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942506">(Mar 26 2020 at 20:14)</a>:</h4>
<p>let me try to remember what the problem was</p>



<a name="191942880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942880">(Mar 26 2020 at 20:17)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/67075" title="https://github.com/rust-lang/rust/issues/67075">https://github.com/rust-lang/rust/issues/67075</a> and <a href="https://github.com/rust-lang/rust/issues/66615" title="https://github.com/rust-lang/rust/issues/66615">https://github.com/rust-lang/rust/issues/66615</a> are the relevant issues</p>



<a name="191942892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191942892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191942892">(Mar 26 2020 at 20:17)</a>:</h4>
<p>and have similar fixes, I imagine</p>



<a name="191943019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943019">(Mar 26 2020 at 20:18)</a>:</h4>
<p>the second issue has some more context</p>



<a name="191943051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943051">(Mar 26 2020 at 20:18)</a>:</h4>
<p>the problem is that, currently, we disambiguate between a const generic path and a type path during name resolution</p>



<a name="191943082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943082">(Mar 26 2020 at 20:18)</a>:</h4>
<p>if we find a type with that name, we treat the parameter as a type parameter; if we find a const with that name, we treat the parameter as a const parameter</p>



<a name="191943121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943121">(Mar 26 2020 at 20:19)</a>:</h4>
<p>however, if we manage to find <em>both</em> names, we have a bit of a problem</p>



<a name="191943144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943144">(Mar 26 2020 at 20:19)</a>:</h4>
<p>because we've got no way of telling yet what it's supposed to be</p>



<a name="191943164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943164">(Mar 26 2020 at 20:19)</a>:</h4>
<p>we won't know until type checking</p>



<a name="191943218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943218">(Mar 26 2020 at 20:20)</a>:</h4>
<p>so I suspect the way to fix this is to have a combined type/const parameter, which could be either, and then disambiguate once we get to type checking</p>



<a name="191943436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943436">(Mar 26 2020 at 20:21)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="218608">@yodal</span> who worked on the initial implementation</p>



<a name="191943553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943553">(Mar 26 2020 at 20:22)</a>:</h4>
<p>I would really like to see this fixed, but I don't think it'll be easy</p>



<a name="191943618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943618">(Mar 26 2020 at 20:22)</a>:</h4>
<p>maybe if you're still keen, <span class="user-mention" data-user-id="216206">@Bastian Kauschke</span>, fixing the <code>()</code> problem could be tried first?<br>
this is simpler, as it doesn't need name resolution at all</p>



<a name="191943632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191943632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191943632">(Mar 26 2020 at 20:23)</a>:</h4>
<p>but would give you some idea of the effort involved</p>



<a name="191944560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191944560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191944560">(Mar 26 2020 at 20:31)</a>:</h4>
<p>as keen as can be. Will look into this</p>



<a name="191945879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191945879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191945879">(Mar 26 2020 at 20:41)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@Bastian Kauschke</span> <span class="user-mention" data-user-id="121053">@varkor</span>  I'd like for <a href="https://github.com/rust-lang/rust/pull/70261" title="https://github.com/rust-lang/rust/pull/70261">https://github.com/rust-lang/rust/pull/70261</a> to land first before making the parser changes</p>



<a name="191945920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191945920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191945920">(Mar 26 2020 at 20:41)</a>:</h4>
<p>cause I'll have some ungreat merge conflicts otherwise</p>



<a name="191945991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191945991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191945991">(Mar 26 2020 at 20:42)</a>:</h4>
<p><span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span> Won't touch the parser for now.</p>



<a name="191946044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191946044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191946044">(Mar 26 2020 at 20:42)</a>:</h4>
<p>parser changes should be minimal if necessary at all, so that shouldn't be a problem</p>



<a name="191946568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191946568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191946568">(Mar 26 2020 at 20:47)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> even small changes in the middle of refactoring a function can be a headache ^^</p>



<a name="191946658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191946658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191946658">(Mar 26 2020 at 20:48)</a>:</h4>
<p>sorry, I meant shouldn't be a problem to let <a href="https://github.com/rust-lang/rust/issues/70261" title="https://github.com/rust-lang/rust/issues/70261">#70261</a> land first</p>



<a name="191946693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191946693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191946693">(Mar 26 2020 at 20:48)</a>:</h4>
<p>ah <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="191956402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/191956402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#191956402">(Mar 26 2020 at 22:20)</a>:</h4>
<p>hir::intravisit::Visitor uses one lifetime for both outer and inner references. <a href="https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_hir/intravisit.rs#L221" title="https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_hir/intravisit.rs#L221">https://github.com/rust-lang/rust/blob/2fbb07525e2f07a815e780a4268b11916248b5a9/src/librustc_hir/intravisit.rs#L221</a></p>
<p>This means that I can't save storage by biilding hir tys and constants  on the fly <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span> <br>
Will look into fixing this later on and just having some duplicate fields for now</p>



<a name="192005875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192005875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192005875">(Mar 27 2020 at 11:42)</a>:</h4>
<p>Should this be forbidden?</p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(const_generics)]</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">arg</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="192005916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192005916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192005916">(Mar 27 2020 at 11:43)</a>:</h4>
<p>compiles rn, even if the default arg can't actually be skipped. <code>type B = A&lt;7&gt;</code> does not work</p>



<a name="192008663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192008663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192008663">(Mar 27 2020 at 12:17)</a>:</h4>
<p>hmm… I think I would expect the declaration, but also <code>type B = A&lt;7&gt;</code> to be accepted</p>



<a name="192008679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192008679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192008679">(Mar 27 2020 at 12:17)</a>:</h4>
<p>it's definitely a case we should explicitly consider though; it's worth opening an issue about</p>



<a name="192164986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192164986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192164986">(Mar 29 2020 at 09:23)</a>:</h4>
<p>e want to allow const default parameters, which afaict are planned like this: <code>struct A&lt;T, U = u32, const N: usize, const M: usize = 7&gt;</code>. </p>
<p>This makes using ambiguous generic args even more cumbersome.</p>
<div class="codehilite"><pre><span></span><span class="c1">// occupy both the ty and the value namespace.</span>
<span class="k">struct</span> <span class="nc">BadBoi</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">field</span>: <span class="kt">u8</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">BadBoi</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">100</span><span class="p">;</span><span class="w"></span>

<span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="n">BadBoi</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="c1">// this would end up as `Type, Ambiguous, Const`.</span>
<span class="c1">// Which allows for both `T, U, N`</span>
<span class="c1">// and `T, N, M`</span>
</pre></div>


<p>zulip code blocks don't have uniform character width <span aria-label="unamused" class="emoji emoji-1f612" role="img" title="unamused">:unamused:</span></p>



<a name="192191861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192191861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192191861">(Mar 29 2020 at 20:10)</a>:</h4>
<p>I made some decent progress here. But currently get mir failures on consts which are completely unused after type resolution.<br>
Is there a way to not build mir for some NodeId?</p>



<a name="192191915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192191915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192191915">(Mar 29 2020 at 20:10)</a>:</h4>
<p>hmm but you want to build MIR</p>



<a name="192191935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192191935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192191935">(Mar 29 2020 at 20:11)</a>:</h4>
<p>my current implementation works like this:<br>
for every ambiguous generic arg, pretend that it is both a const and a type.<br>
Once it is clear what the arg is, discard the unused interpretation.</p>



<a name="192191984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192191984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192191984">(Mar 29 2020 at 20:12)</a>:</h4>
<p>who disambiguates?</p>



<a name="192191993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192191993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192191993">(Mar 29 2020 at 20:12)</a>:</h4>
<p>if it's typeck, I don't think that's accepetable</p>



<a name="192192068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192068">(Mar 29 2020 at 20:14)</a>:</h4>
<p>hmm apparently librustc_ast_lowering</p>



<a name="192192072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192072">(Mar 29 2020 at 20:14)</a>:</h4>
<p>wait a sec</p>



<a name="192192073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192073">(Mar 29 2020 at 20:14)</a>:</h4>
<p>that should be fine</p>



<a name="192192075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192075">(Mar 29 2020 at 20:14)</a>:</h4>
<p><code>librustc_ast_lowering</code> should be able to discard the const side if it's a type</p>



<a name="192192155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192155">(Mar 29 2020 at 20:16)</a>:</h4>
<p>never mind, it's not ast_lowering. I can't find the file which does the disambiguation rn. DID I ACCIDENTALLY REVERT THESE CHANGES <span aria-label="cry" class="emoji emoji-1f622" role="img" title="cry">:cry:</span></p>



<a name="192192223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192223">(Mar 29 2020 at 20:18)</a>:</h4>
<p>wtf did I do</p>



<a name="192192332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192332">(Mar 29 2020 at 20:21)</a>:</h4>
<p>it's <code>librustc_typeck::astconv</code> instead, <a href="https://github.com/rust-lang/rust/blob/285519d412ef9c65df3bcd2de2b1a3d6ca16a255/src/librustc_typeck/astconv.rs#L584-L618" title="https://github.com/rust-lang/rust/blob/285519d412ef9c65df3bcd2de2b1a3d6ca16a255/src/librustc_typeck/astconv.rs#L584-L618">https://github.com/rust-lang/rust/blob/285519d412ef9c65df3bcd2de2b1a3d6ca16a255/src/librustc_typeck/astconv.rs#L584-L618</a></p>



<a name="192192881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192192881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192192881">(Mar 29 2020 at 20:34)</a>:</h4>
<p>Meaning thait is after typeck. Considering that we don't know what params we need before this I doubt that we can do it any other way without requiring a different syntax.</p>



<a name="192193121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192193121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192193121">(Mar 29 2020 at 20:39)</a>:</h4>
<p>that's why there are braces</p>



<a name="192193157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192193157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192193157">(Mar 29 2020 at 20:40)</a>:</h4>
<p>for arbitrary expressions</p>



<a name="192193175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192193175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192193175">(Mar 29 2020 at 20:40)</a>:</h4>
<p>anyway you should get <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> on-board with this</p>



<a name="192193178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192193178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192193178">(Mar 29 2020 at 20:40)</a>:</h4>
<p>it may still be possible to do in AST-&gt;HIR lowering</p>



<a name="192194740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192194740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192194740">(Mar 29 2020 at 21:18)</a>:</h4>
<p>That's disheartening, especially since this approach was previously mentioned by @varkor.<br>
I do agree that it causes a lot of complexity for a smallish improvement, even if it would work.</p>
<p>Afaict at least type inference is required for this to work for all paths. Another approach would be to do this on a best effort basis<br>
and improve diagnostics in places where it is ambiguous, which would be easier to implement, even if it is unfortunate.</p>
<p>Will stop working on this problem until some kind of decision is made here.</p>



<a name="192196625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196625">(Mar 29 2020 at 22:08)</a>:</h4>
<p>There's not much that can be done here before type checking.</p>



<a name="192196631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196631">(Mar 29 2020 at 22:08)</a>:</h4>
<p>(I'm talking only about paths, not additional stuff like <code>()</code> type vs <code>()</code> expr.)</p>



<a name="192196647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196647">(Mar 29 2020 at 22:09)</a>:</h4>
<p>First, <a href="https://github.com/rust-lang/rust/pull/66104#discussion_r344450671" title="https://github.com/rust-lang/rust/pull/66104#discussion_r344450671">https://github.com/rust-lang/rust/pull/66104#discussion_r344450671</a> could potentially be fixed to support disambiguating <code>ident&lt;Args&gt;</code> in addition to just <code>ident</code>.</p>



<a name="192196786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196786">(Mar 29 2020 at 22:12)</a>:</h4>
<p>Second, <em>some</em> multi-segment paths can be disambiguated, e.g. for <code>module::Name</code> it's clear before type checking whether <code>Name</code> is a type, or value, or both (assuming <code>module</code> is a module), but for paths potentially involving associated items we cannot disambiguate until type checking.</p>



<a name="192196816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196816">(Mar 29 2020 at 22:13)</a>:</h4>
<p>If someone prototypes the disambiguation during type checking, that would be great, I think it should be pretty realistic?</p>



<a name="192196861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192196861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192196861">(Mar 29 2020 at 22:14)</a>:</h4>
<p>You'll have to keep something like two paths in HIR until then though.</p>



<a name="192197049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197049">(Mar 29 2020 at 22:20)</a>:</h4>
<p>hmm, but you can't resolve an associated value (const/fn) outside of a body, and associated types are, well, terribly supported</p>



<a name="192197730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197730">(Mar 29 2020 at 22:39)</a>:</h4>
<p>there are some cases you can't disambiguate before type checking, because it's ambiguous</p>



<a name="192197735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197735">(Mar 29 2020 at 22:39)</a>:</h4>
<p>these are the cases I was suggesting to <span class="user-mention" data-user-id="216206">@Bastian Kauschke</span> we wanted to be fixed</p>



<a name="192197775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197775">(Mar 29 2020 at 22:40)</a>:</h4>
<p>for example, if we have a const and a type with the same name, we can't distinguish between them until type checking, because we don't know which it's supposed to be</p>



<a name="192197787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197787">(Mar 29 2020 at 22:41)</a>:</h4>
<p>there are definitely some improvements we can make before type checking, e.g. the improvements <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> suggests, but these aren't going to cover all cases</p>



<a name="192197804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197804">(Mar 29 2020 at 22:41)</a>:</h4>
<blockquote>
<p>that's why there are braces</p>
</blockquote>
<p>asking a user to use braces <em>only if</em> there's a type with the same name is very confusing, I think</p>



<a name="192197847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197847">(Mar 29 2020 at 22:42)</a>:</h4>
<p>especially as it isn't ambiguous</p>



<a name="192197890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197890">(Mar 29 2020 at 22:43)</a>:</h4>
<blockquote>
<p>this would end up as <code>Type, Ambiguous, Const</code>.</p>
</blockquote>
<p>okay, this is unfortunate</p>



<a name="192197894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197894">(Mar 29 2020 at 22:44)</a>:</h4>
<p>but this is a design problem more than an implementation problem</p>



<a name="192197936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197936">(Mar 29 2020 at 22:44)</a>:</h4>
<p>I think the sensible thing is to default to types if possible</p>



<a name="192197938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197938">(Mar 29 2020 at 22:44)</a>:</h4>
<p>e.g. we only try it as a const if we would get an error otherwise</p>



<a name="192197939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197939">(Mar 29 2020 at 22:44)</a>:</h4>
<p>this should be consistent and fairly intuitive</p>



<a name="192197941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192197941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192197941">(Mar 29 2020 at 22:44)</a>:</h4>
<p>it's also an edge case</p>



<a name="192199286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192199286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192199286">(Mar 29 2020 at 23:23)</a>:</h4>
<p>yeah and {} is the override</p>



<a name="192199303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192199303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192199303">(Mar 29 2020 at 23:24)</a>:</h4>
<p>to pick the value instead</p>



<a name="192199611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192199611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192199611">(Mar 29 2020 at 23:33)</a>:</h4>
<p>yes, but if it's unambiguous, I don't think you should have to override</p>



<a name="192200388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200388">(Mar 29 2020 at 23:55)</a>:</h4>
<p>depends where the context is coming from, idk</p>



<a name="192200431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200431">(Mar 29 2020 at 23:56)</a>:</h4>
<p>overall it's pretty finicky rn</p>



<a name="192200436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200436">(Mar 29 2020 at 23:56)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> not to mention that once the WF checks are properly in place, most examples will start to fall apart regardless</p>



<a name="192200439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200439">(Mar 29 2020 at 23:56)</a>:</h4>
<p>like e.g. <code>Foo&lt;{T::CONST}&gt;</code></p>



<a name="192200465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200465">(Mar 29 2020 at 23:57)</a>:</h4>
<p>I'm interested in cases where we have a struct <code>S</code> and we want to pass the value <code>S</code> as a const argument</p>



<a name="192200512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200512">(Mar 29 2020 at 23:58)</a>:</h4>
<p>this is WF, but only works if we allow disambiguation during type checking</p>



<a name="192200518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200518">(Mar 29 2020 at 23:58)</a>:</h4>
<p>because otherwise we interpret it as the type <code>S</code></p>



<a name="192200523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192200523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192200523">(Mar 29 2020 at 23:58)</a>:</h4>
<p>(which is the same problem as accepting <code>()</code>)</p>



<a name="192222834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/192222834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#192222834">(Mar 30 2020 at 08:04)</a>:</h4>
<blockquote>
<p>If someone prototypes the disambiguation during type checking, that would be great, I think it should be pretty realistic?</p>
</blockquote>
<p>I have a (not yet working) prototype which pretends like ambiguous args are both a type and a const and then discards the unused one after typeck.</p>
<p>I can try and get this to work. But I don't believe that it's worth my time if eddyb is this strongly against this.<br>
@eddyb:</p>
<blockquote>
<p>if it's typeck, I don't think that's accepetable</p>
</blockquote>



<a name="195350507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/195350507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#195350507">(Apr 26 2020 at 20:10)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> AST lowering happens before we start using queries queries, doesn't it <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span> </p>
<p>If not, we could use the same approach as <a href="https://github.com/rust-lang/rust/pull/71154" title="https://github.com/rust-lang/rust/pull/71154">https://github.com/rust-lang/rust/pull/71154</a> for ambiguous generic arguments,<br>
which would be a fairly clean solution.</p>



<a name="195350665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/195350665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#195350665">(Apr 26 2020 at 20:15)</a>:</h4>
<p>i.e. <code>lower_generic_arg(arg)</code> -&gt; <code>typeck_tables_of(surrounding_body)</code>-&gt; <code>lower_generic_arg_with_kind(arg, ArgKind::Const/Type)</code></p>



<a name="195350724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/195350724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#195350724">(Apr 26 2020 at 20:16)</a>:</h4>
<p>as we only need to use generic arguments during typeck once we know the corresponding context</p>



<a name="195400025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/195400025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#195400025">(Apr 27 2020 at 10:46)</a>:</h4>
<p>as I understand it, the plan has always been to pull queries back as early as possible (I believe this was something <span class="user-mention" data-user-id="116466">@Zoxc</span> was working on), but I'm not sure how far it got</p>



<a name="195453305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/const-generics%3A%20literal%20params/near/195453305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/const-generics.3A.20literal.20params.html#195453305">(Apr 27 2020 at 17:56)</a>:</h4>
<p>This PR might be of interest to the people in this topic: <a href="https://github.com/rust-lang/rust/pull/71592" title="https://github.com/rust-lang/rust/pull/71592">https://github.com/rust-lang/rust/pull/71592</a><br>
It starts parsing unambiguous const expressions without braces (things that start with a literal and are simple expressions). It also adds some partial recovery and suggestion for some common missing braces errors. It should inform a bit of what changes would be required to accept things like <code>A + B</code>, <code>A - B</code> and <code>A::B()</code> without changing anything else. It seems doable, but don't know if it is worth it to complicate the semantics to do so.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>